<script setup lang="ts">
import { ref, onMounted, onUnmounted } from "vue";
import { ElMessage } from "element-plus";

// 固定性能数据（根据用户提供的表格，21个指标）
const performanceData = ref([
  {
    deviceName: "杭州交运至上海骨干24波QX002599-OCH:1",
    indicator: "色散补偿当前值(ps/nm)",
    type: "15分钟",
    time: "2025-09-24 21:00:00",
    maxValue: "3600.00",
    avgValue: "3588.00",
    minValue: "3583.00",
    status: "有效"
  },
  {
    deviceName: "杭州交运至上海骨干24波QX002599-OCH:1",
    indicator: "激光器偏置电流当前值(mA)",
    type: "15分钟",
    time: "2025-09-24 21:00:00",
    maxValue: "51.00",
    avgValue: "51.00",
    minValue: "51.00",
    status: "有效"
  },
  {
    deviceName: "杭州交运至上海骨干24波QX002599-OCH:1",
    indicator: "激光器工作温度当前值(℃)",
    type: "15分钟",
    time: "2025-09-24 21:00:00",
    maxValue: "44.90",
    avgValue: "44.90",
    minValue: "44.90",
    status: "有效"
  },
  {
    deviceName: "杭州交运至上海骨干24波QX002599-OCH:1",
    indicator: "激光器制冷电流当前值(mA)",
    type: "15分钟",
    time: "2025-09-24 21:00:00",
    maxValue: "7.00",
    avgValue: "7.00",
    minValue: "7.00",
    status: "有效"
  },
  {
    deviceName: "杭州交运至上海骨干24波QX002599-OCH:1",
    indicator: "差分群时延平均值(ps)",
    type: "15分钟",
    time: "2025-09-24 21:00:00",
    maxValue: "-",
    avgValue: "4.10",
    minValue: "-",
    status: "有效"
  },
  {
    deviceName: "杭州交运至上海骨干24波QX002599-OCH:1",
    indicator: "总输入光功率当前值(dBm)",
    type: "15分钟",
    time: "2025-09-24 21:00:00",
    maxValue: "-5.90",
    avgValue: "-5.90",
    minValue: "-5.90",
    status: "有效"
  },
  {
    deviceName: "杭州交运至上海骨干24波QX002599-OCH:1",
    indicator: "激光器输出光功率当前值(dBm)",
    type: "15分钟",
    time: "2025-09-24 21:00:00",
    maxValue: "-2.70",
    avgValue: "-2.70",
    minValue: "-2.70",
    status: "有效"
  },
  {
    deviceName: "杭州交运至上海骨干24波QX002599-OCH:1",
    indicator: "差分群时延当前值(ps)",
    type: "15分钟",
    time: "2025-09-24 21:00:00",
    maxValue: "5.00",
    avgValue: "4.00",
    minValue: "3.00",
    status: "有效"
  },
  {
    deviceName: "杭州交运至上海骨干24波QX002599-OCH:1",
    indicator: "激光器输入光功率当前值(dBm)",
    type: "15分钟",
    time: "2025-09-24 21:00:00",
    maxValue: "-5.90",
    avgValue: "-5.90",
    minValue: "-5.90",
    status: "有效"
  },
  {
    deviceName: "杭州交运至上海骨干24波QX002599-OCH:1-OTU4:1",
    indicator: "FEC纠正的0bit计数",
    type: "15分钟",
    time: "2025-09-24 21:00:00",
    maxValue: "-",
    avgValue: "49237053",
    minValue: "-",
    status: "有效"
  },
  {
    deviceName: "杭州交运至上海骨干24波QX002599-OCH:1-OTU4:1",
    indicator: "FEC纠正的1bit计数",
    type: "15分钟",
    time: "2025-09-24 21:00:00",
    maxValue: "-",
    avgValue: "49237386",
    minValue: "-",
    status: "有效"
  },
  {
    deviceName: "杭州交运至上海骨干24波QX002599-OCH:1-OTU4:1",
    indicator: "FEC纠正的字节计数",
    type: "15分钟",
    time: "2025-09-24 21:00:00",
    maxValue: "-",
    avgValue: "98474439",
    minValue: "-",
    status: "有效"
  },
  {
    deviceName: "杭州交运至上海骨干24波QX002599-OCH:1-OTU4:1",
    indicator: "FEC纠错前的误码率",
    type: "15分钟",
    time: "2025-09-24 21:00:00",
    maxValue: "-",
    avgValue: "4",
    minValue: "-",
    status: "有效"
  },
  {
    deviceName: "杭州交运至上海骨干24波QX002599-OCH:1-OTU4:1",
    indicator: "FEC纠错后的误码率",
    type: "15分钟",
    time: "2025-09-24 21:00:00",
    maxValue: "-",
    avgValue: "0",
    minValue: "-",
    status: "有效"
  },
  {
    deviceName: "杭州交运至上海骨干24波QX002599-OCH:1-OTU4:1",
    indicator: "FEC纠错前误码率（浮点）",
    type: "15分钟",
    time: "2025-09-24 21:00:00",
    maxValue: "-",
    avgValue: "3.000e-04(Q=10.71dB)",
    minValue: "-",
    status: "有效"
  },
  {
    deviceName: "杭州交运至上海骨干24波QX002599-OCH:1-OTU4:1",
    indicator: "FEC纠错后误码率（浮点）",
    type: "15分钟",
    time: "2025-09-24 21:00:00",
    maxValue: "-",
    avgValue: "0(Q over 18dB)",
    minValue: "-",
    status: "有效"
  },
  {
    deviceName: "杭州交运至上海骨干24波QX002599-OCH:1-OTU4:1",
    indicator: "FEC纠错后平均误码率",
    type: "15分钟",
    time: "2025-09-24 21:00:00",
    maxValue: "-",
    avgValue: "0",
    minValue: "-",
    status: "有效"
  },
  {
    deviceName: "杭州交运至上海骨干24波QX002599-OCH:1-OTU4:1",
    indicator: "FEC纠错前平均误码率",
    type: "15分钟",
    time: "2025-09-24 21:00:00",
    maxValue: "-",
    avgValue: "4",
    minValue: "-",
    status: "有效"
  },
  {
    deviceName: "杭州交运至上海骨干24波QX002599-OCH:1-OTU4:1",
    indicator: "OTU4的SM段总计监控周期(s)",
    type: "15分钟",
    time: "2025-09-24 21:00:00",
    maxValue: "-",
    avgValue: "653.00",
    minValue: "-",
    status: "有效"
  },
  {
    deviceName: "杭州交运至上海骨干24波QX002599-OCH:1-ODU4:1",
    indicator: "ODU4的PM段总计监控周期(s)",
    type: "15分钟",
    time: "2025-09-24 21:00:00",
    maxValue: "-",
    avgValue: "653.00",
    minValue: "-",
    status: "有效"
  },
  {
    deviceName: "杭州交运至上海骨干24波QX002599-OCH:1-ODU4:1-ODUflex:1",
    indicator: "ODUFLEX的PM段总计监控周期(s)",
    type: "15分钟",
    time: "2025-09-24 21:00:00",
    maxValue: "-",
    avgValue: "653.00",
    minValue: "-",
    status: "有效"
  }
]);

const currentIndex = ref(0);
let intervalId = null;

const startCarousel = () => {
  intervalId = setInterval(() => {
    currentIndex.value = (currentIndex.value + 1) % performanceData.value.length;
  }, 5000); // 每3秒切换
};

onMounted(() => {
  startCarousel();
});

onUnmounted(() => {
  if (intervalId) clearInterval(intervalId);
});
</script>

<template>
  <div class="performance-monitor">
    <transition name="fade" mode="out-in">
      <div v-if="performanceData.length > 0" :key="currentIndex" class="device-card">
        <p>设备： {{ performanceData[currentIndex].deviceName }}</p>
        <p>指标： {{ performanceData[currentIndex].indicator }}</p>
<!--        <p>类型： {{ performanceData[currentIndex].type }}</p>-->
<!--        <p>时间： {{ performanceData[currentIndex].time }}</p>-->
        <p>最大值： {{ performanceData[currentIndex].maxValue }}</p>
        <p>平均值： {{ performanceData[currentIndex].avgValue }}</p>
        <p>最小值： {{ performanceData[currentIndex].minValue }}</p>
        <p>状态： {{ performanceData[currentIndex].status }}</p>
      </div>
      <div v-else class="no-data">
        <p>暂无性能数据</p>
      </div>
    </transition>
  </div>
</template>

<style scoped lang="scss">
.performance-monitor {
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  box-sizing: border-box;
}

.device-card {
  background: rgba(0, 0, 0, 0.5);
  border-radius: 8px;
  padding: 20px;
  width: 100%;
  text-align: left;
  color: #fff;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  transition: all 0.3s ease;
  font-size: 14px;
  line-height: 1.6;
  
  p {
    margin: 4px 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
}

.no-data {
  color: #999;
  font-size: 16px;
}

.fade-enter-active, .fade-leave-active {
  transition: opacity 0.5s ease;
}

.fade-enter-from, .fade-leave-to {
  opacity: 0;
}
</style>
